package com.practice.springboot_01_zwj.scheduled;

// ImportController.java 控制器

import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ImportController {

    public enum ImportType {
        EIGHT_RATE,
        INCOME_QUESTION,
        THREE_HUNDRED
    }

    @Autowired
    private EightRateImporterService eightRateService;

    @Autowired
    private IncomeQuestionImportService incomeQuestionService;

    @Autowired
    private ThreeHundredImportService threeHundredService;

    /**
     * 统一导入接口
     * @param filePath 文件路径（例如：D:/data/file.txt）
     * @param type 导入类型枚举值：EIGHT_RATE, INCOME_QUESTION, THREE_HUNDRED
     */
    @PostMapping("/import")
    public String unifiedImport(
            @RequestParam String filePath,
            @RequestParam ImportType type
    ) {
        switch (type) {
            case EIGHT_RATE:
                new Thread(() -> eightRateService.importLargeFile(filePath)).start();
                return "健康八率导入任务已开始";
            case INCOME_QUESTION:
                new Thread(() -> incomeQuestionService.importLargeFile(filePath)).start();
                return "收入问题导入任务已开始";
            case THREE_HUNDRED:
                new Thread(() -> threeHundredService.importLargeFile(filePath)).start();
                return "三百万项目导入任务已开始";
            default:
                return "未知的导入类型";
        }
    }
}